/****************************************************************************
 *
 * Copyright (C) 2003-2008 Los Alamos National Security, LLC
 *                         Packet Analytics Corporation
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License Version 2 as
 * published by the Free Software Foundation.  You may not use, modify or
 * distribute this program under any other version of the GNU General
 * Public License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 ****************************************************************************/
package nfse.gui.record;

import com.google.gwt.user.client.rpc.IsSerializable;

public class FlexRecordGroup implements IsSerializable {

    public int typeID = -1;

    public String typeName = "";

    public FlexRecord[] records = null;

    public FlexRecordField[] flexRecordFields = null;

    public int starttsIdx = -1;

    public FlexRecordGroup() {
        
    }

    public String[] getFieldNames() {
        String[] temp = new String[flexRecordFields.length];
        for (int i = 0; i < temp.length; i++) {
            temp[i] = flexRecordFields[i].name;
        }
        return temp;
    }

    public String[] getColumnNames() {
        if (flexRecordFields == null || flexRecordFields.length == 0)
            return new String[0];

        String[] temp = new String[flexRecordFields.length];
        for (int i = 0; i < temp.length; i++) {
            temp[i] = flexRecordFields[i].columnName;
        }
        return temp;
    }

    public int[] getColumnWidths() {
        int colCount = getColumnNames().length;
        int[] temp = new int[colCount];
        for (int i = 0; i < colCount; i++)
            temp[i] = 75;
        return temp;
    }

    public int getRecordCount() {
        if (records == null)
            return 0;
        return records.length;
    }

    public FlexRecord getRecord(int idx) {
        if (records == null || idx < 0 || idx >= records.length)
            return null;
        return records[idx];
    }

    public int getStartTSIdx() {
        if (starttsIdx == -1) {
            String[] names = getColumnNames();
            for (int i = 0; i < names.length; i++) {
                if (names[i].equals("startts")) {
                    starttsIdx = i;
                    break;
                }
            }
        }
        return starttsIdx;
    }

    public int getFieldIdx(String name) {
        int idx = -1;
        String[] names = getColumnNames();
        for (int i = 0; i < names.length; i++) {
            if (names[i].equals(name)) {
                idx = i;
                break;
            }
        }
        return idx;
    }

}
